/*
 * > /*
 >  * INSANE - Interactive Structural Analysis Environment
 >  *
 >  * Copyright (C) 2003-2004
 >  * Universidade Federal de Minas Gerais
 >  * Escola de Engenharia
 >  * Departamento de Engenharia de Estruturas
 >  *
 >  * Author's email :     insane@dees.ufmg.br
 >  * Author's Website :   http://www.dees.ufmg.br/insane
 >  *
 >  * This program is free software; you can redistribute it and/or
 >  * modify it under the terms of the GNU General Public License
 >  * as published by the Free Software Foundation; either version 2
 >  * of the License, or any later version.
 >  *
 >  * This program is distributed in the hope that it will be useful,
 >  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 >  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 >  * GNU General Public License for more details.
 >  *
 >  * You should have received a copy of the GNU General Public License
 >  * along with this program; if not, write to the Free Software
 >  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 > 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.postp.postp_view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;

import javax.help.HelpBroker;
import javax.help.HelpSet;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.plaf.FontUIResource;

import br.ufmg.dees.insane.commons.InsaneProperties;
import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.command.CommandHolder;
import br.ufmg.dees.insane.commons.view.CmdButton;
import br.ufmg.dees.insane.commons.view.CmdCheckBoxMenu;
import br.ufmg.dees.insane.commons.view.CmdMenu;
import br.ufmg.dees.insane.commons.view.IView;
import br.ufmg.dees.insane.commons.view.ModelList;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.AnimationStartStepCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.AnimationStopStepCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.BackwardStepCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.DiscontinuosElementsContourSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.DisplayCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.DistortCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.EigenvaluesElementsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.EigenvaluesNodalsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ElementsContourSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ElementsSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ExitCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ExportJPEGCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ExportPNGCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ExportPSCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ExportXMLCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.FaceSettingsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.FitCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ForwardStepCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.GaussSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.GeneralSettingsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.GraphicCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.HelpCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ImportFemBinCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ImportFemXMLCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ImportPostpXMLCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.InformationCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.LastZoomCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.LoadFemModelBinCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.LoadFemModelXMLCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.LoadPostpXMLCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.MeshStateListCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ModelSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.MoveCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.MoveDownCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.MoveLeftCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.MoveRightCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.MoveUpCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.NodalContourSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.NodesSelectionCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.OpenCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.RedrawCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SaveFileAsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SaveFileCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ScaleColorsSettingsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetPerspectiveCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetPlanXYCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetPlanXZCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetPlanYZCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetRotationXCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetRotationYCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetRotationZCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.SetStepCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.VectorResultsElementsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.VectorResultsNodalsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.VerticesSettingsCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ViewGlobalAxisCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ZoomAllCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ZoomCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ZoomInCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.command.ZoomOutCommand;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.dialog.DecimalField;

/**
 * @author Samuel Silva Penna
 * @since 05/07/2005
 */
public class DesktopPostp extends JFrame implements ActionListener {
	
	/**   */
	private static final long serialVersionUID = 1L;
	
	private IView view = new DesktopView(this);
	private ArrayList views = new ArrayList();
	private InsaneProperties  properties = new InsaneProperties();
	private int internalFramesCount = 0;
	private ModelList modelList = new ModelList();
	
	//Main panel
	private JDesktopPane desktop = new JDesktopPane();
	
	//Commands
	private Command meshStateListCmd = new MeshStateListCommand(this);
	private Command nodalPlotContoursCmd = new NodalContourSelectionCommand(this);
	private Command eigevaluesNodalsCmd = new EigenvaluesNodalsCommand(this);
	private Command vectorsResultsNodalsCmd = new VectorResultsNodalsCommand(this);
	
	private Command elementsPlotContoursCmd = new ElementsContourSelectionCommand(this);
	private Command discontinuosElementsPlotContoursCmd = new DiscontinuosElementsContourSelectionCommand(this);
	private Command eigevaluesElementsCmd = new EigenvaluesElementsCommand(this);
	private Command vectorsResultsElementssCmd = new VectorResultsElementsCommand(this);
	
	private Command informationCmd = new InformationCommand(this);
	//private Command graphicSettingsCmd = new GraphicSettingsCommand(this);
	private Command graphicCmd = new GraphicCommand(this);
	private Command openCmd = new OpenCommand(this);
	private Command saveFileCmd = new SaveFileCommand(this);
	private Command saveFileAsCmd = new SaveFileAsCommand(this);
	private Command importFemBinCmd = new ImportFemBinCommand(this);
	private Command importFemXMLCmd = new ImportFemXMLCommand(this);
	private Command importPostpXMLCmd = new ImportPostpXMLCommand(this);
	private Command exportXMLCmd = new ExportXMLCommand(this);
	private Command loadFemModelBinCmd = new LoadFemModelBinCommand(this);
	private Command loadFemModelXMLCmd = new LoadFemModelXMLCommand(this);
	private Command loadPostpXMLCmd = new LoadPostpXMLCommand(this);
	private Command exportJPEGCmd = new ExportJPEGCommand(this);
	private Command exportPNGCmd = new ExportPNGCommand(this);
	private Command exportPSCmd = new ExportPSCommand(this);
	private Command modelSelectionCmd = new ModelSelectionCommand(this);
	private Command exitCmd = new ExitCommand(this);
	private Command genSettingsCmd = new GeneralSettingsCommand(this);
	private Command faceSettingsCmd = new FaceSettingsCommand(this);
	private Command verticesSettingsCmd = new VerticesSettingsCommand(this);
	private Command scaleColorsSettingsCmd = new ScaleColorsSettingsCommand(this);
	private Command displayCmd = new DisplayCommand(this);
	private Command helpCmd = new HelpCommand(this);
	private Command moveCmd = new MoveCommand(this);
	private Command viewGlobalAxisCmd = new ViewGlobalAxisCommand(this);
	
	private Command elementsSelectionCmd = new ElementsSelectionCommand(this);
	private Command nodesSelectionCmd = new NodesSelectionCommand(this);
	private Command gaussSelectionCmd = new GaussSelectionCommand(this);
	private Command distortCmd = new DistortCommand(this);
	
	private Command zoomCmd = new ZoomCommand();
	private Command zoomInCmd = new ZoomInCommand();
	private Command zoomOutCmd = new ZoomOutCommand();
	private Command fitCmd = new FitCommand();
	private Command zoomAllCmd = new ZoomAllCommand();
	private Command lastZoomCmd = new LastZoomCommand();
	private Command redrawCmd = new RedrawCommand();
	private Command setPlanXYCmd = new SetPlanXYCommand();
	private Command setPlanXZCmd = new SetPlanXZCommand();
	private Command setPlanYZCmd = new SetPlanYZCommand();
	private Command setPerspectiveCmd = new SetPerspectiveCommand();
	private Command setRotationXCmd = new SetRotationXCommand();
	private Command setRotationYCmd = new SetRotationYCommand();
	private Command setRotationZCmd = new SetRotationZCommand();
	private Command forwardStepCmd = new ForwardStepCommand();
	private Command backwardStepCmd = new BackwardStepCommand();
	private Command setStepCmd = new SetStepCommand();
	private Command startAnimationStepCmd = new AnimationStartStepCommand();
	private Command stopAnimationStepCmd = new AnimationStopStepCommand();
	
	private Command moveUpCmd = new MoveUpCommand();
	private Command moveLeftCmd = new MoveLeftCommand();
	private Command moveRightCmd = new MoveRightCommand();
	private Command moveDownCmd = new MoveDownCommand();
	
	//Menu
	private JMenuBar menuBar = new JMenuBar();
	//Menu File
	private JMenu menuFile = new JMenu("File");
	private CmdMenu itemOpen = new CmdMenu("Open", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Open16.gif")));
	private CmdMenu itemSave = new CmdMenu("Save", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Save16.gif")));
	private CmdMenu itemSaveAs = new CmdMenu("Save As", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SaveAs16.gif")));
	private CmdMenu itemPrint = new CmdMenu("Print", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Print16.gif")));
	private JMenu menuExport = new JMenu("Export");
	private CmdMenu itemJPEG = new CmdMenu("JPEG Image", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
	private CmdMenu itemPNG = new CmdMenu("PNG Image", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
	private CmdMenu itemPS = new CmdMenu("PostScript", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
	private CmdMenu itemXML = new CmdMenu("XML File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
	private JMenu menuImport = new JMenu("Import");
	private CmdMenu itemFemBinaryFiles = new CmdMenu("Fem Model Binary File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	private CmdMenu itemFemXMLFiles= new CmdMenu("Fem Model XML File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	private CmdMenu itemPostpXMLFiles = new CmdMenu("Postp Model XML File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	private CmdMenu itemExit = new CmdMenu("Exit");
	private JMenu menuLoad = new JMenu("Load Data");
	private CmdMenu itemLoadFemBinFile = new CmdMenu("...  Fem Model Binary Files", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	private CmdMenu itemLoadFemXMLFile = new CmdMenu("...  Fem Model XML Files", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	private CmdMenu itemLoadPostpXMLFile = new CmdMenu("...  Postp Model XML Files", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	//Menu View
	private JMenu menuView = new JMenu("View");
	private CmdMenu itemModelsSelection = new CmdMenu("Model Selection");
	private CmdMenu itemDisplay = new CmdMenu("Display");
	private JMenu menuZoom = new JMenu("Zoom");
    private CmdMenu itemWindow = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Zoom16.gif")));
    private CmdMenu itemZoomIn = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomIn16.gif")));
    private CmdMenu itemZoomOut = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomOut16.gif")));
    private CmdMenu itemExtents = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomExtents16.gif")));
    private CmdMenu itemAll = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomAll16.gif")));
    private CmdMenu itemLastZoom = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomPrevious16.gif")));
	private CmdMenu itemRedraw = new CmdMenu(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redraw16.gif")));
	//private CmdMenu itemProjections = new CmdMenu("Projections");
	//private CmdMenu itemRotation = new CmdMenu("Rotation");
	private CmdMenu itemMove = new CmdMenu("Move");
	private CmdCheckBoxMenu itemViewGlobalAxis = new CmdCheckBoxMenu("View Global Axis");
	//private CmdCheckBoxMenu itemViewLocalAxis = new CmdCheckBoxMenu();
	//Menu Settings
	private JMenu menuSettings = new JMenu("Settings");
	private CmdMenu itemGenSettings = new CmdMenu("General Settings");
	private CmdMenu itemFaceSettings = new CmdMenu("Face Settings");
	private CmdMenu itemEdgesSettings = new CmdMenu("Edge Settings");
	private CmdMenu itemVertexSettings = new CmdMenu("Vertex Settings");
//	private CmdMenu itemViewAttributesSettings = new CmdMenu("View Settings");
//	private CmdMenu itemRestraints = new CmdMenu("Restraints Settings");
//	private CmdMenu itemLoads = new CmdMenu("Loads Settings");
	private CmdMenu itemScaleColorsSettings = new CmdMenu("Scale Colors Settings");
	//private CmdMenu itemGraphicsSettings = new CmdMenu("Graphics Settings");
	//Menu View Results
	private JMenu menuResults = new JMenu("Results");
	private JMenu menuNodalResults = new JMenu("Nodals Results");
	private CmdMenu itemNodalPlotContours = new CmdMenu("Nodal Contours");
	private CmdMenu itemNodalEigenvalues = new CmdMenu("Compose Eigenvalues");
	private CmdMenu itemNodalVector = new CmdMenu("Compose Vectors Results");
	private JMenu menuElementResults = new JMenu("Elements Results");
	private CmdMenu itemElementsPlotContours = new CmdMenu("Smootheness Contours");
	private CmdMenu itemElementEigenvalues = new CmdMenu("Compose Eigenvalues");
	private CmdMenu itemElementVector = new CmdMenu("Compose Vectors Results");
	private CmdMenu itemDiscontinuosElementsPlotContours = new CmdMenu("Discontinuos Contours");
	private CmdMenu itemGraph = new CmdMenu("Graphic");
	private CmdMenu itemMeshState = new CmdMenu("Mesh State");
	private CmdMenu itemInformation = new CmdMenu("Information");
//	private CmdMenu itemNodalReport = new CmdMenu("Nodal Report");
//	private CmdMenu itemElementReport = new CmdMenu("Element Report");
//	private CmdMenu itemModelReport = new CmdMenu("Model Report");
	//Menu Help
	private JMenu menuHelp = new JMenu("Help");
	private CmdMenu itemHelp = new CmdMenu("Open", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Open16.gif")));
	
	//Tools
	private JPanel toolPanel = new JPanel();
	
	private JToolBar zoomToolBar = new JToolBar();
	private CmdButton fit = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomExtents16.gif")));
	private CmdButton zoom = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Zoom16.gif")));
	private CmdButton zoomIn = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomIn16.gif")));
	private CmdButton zoomOut = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomOut16.gif")));
	private CmdButton zoomAll = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomAll16.gif")));
	private CmdButton zoomPrevious = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomPrevious16.gif")));
	private CmdButton redraw = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redraw16.gif")));
	
	private JToolBar planBar = new JToolBar();
	private CmdButton xyPlanButton = new CmdButton(" XY ");
	private CmdButton xzPlanButton = new CmdButton(" XZ ");
	private CmdButton yzPlanButton = new CmdButton(" YZ ");
	private CmdButton perspectiveButton = new CmdButton("  P  ");
	private CmdButton xRotationButton = new CmdButton(" RotX ");
	private CmdButton yRotationButton = new CmdButton(" RotY ");
	private CmdButton zRotationButton = new CmdButton(" RotZ ");
	private DecimalField setAngleStepField ;
	private DecimalField setMoveStepField ;
	
	private JToolBar stepModeBar = new JToolBar();
	private CmdButton forwardButton = new CmdButton("Step + >>");
	private DecimalField currentStepField;
	private CmdButton backwardButton = new CmdButton("<< - Step");
	private CmdButton goToStepButton = new CmdButton("Set Step");
	private DecimalField setStepField;
	private CmdButton startButton = new CmdButton("Start Animation");
	private CmdButton stopButton = new CmdButton("Stop Animation");
	
	private JPanel hToolPanel = new JPanel();
	
	private JToolBar vToolBar = new JToolBar();
	
	private CmdButton upButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/UP.gif")));
	private CmdButton leftButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Left.gif")));
	private CmdButton rightButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Right.gif")));
	private CmdButton downButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Down.gif")));
	
	private CmdButton nodalResultsButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stress.gif")));
	
	private CmdButton elementsResultsButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/StressElement.gif")));
	
	private CmdButton meshStateButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Deform.gif")));
	private CmdButton graphButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/graph.gif")));
	private CmdButton infoButton = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Information24.gif")));
	
	private CmdButton elementSelctionButton = new CmdButton(" E ");
	private CmdButton nodalSelectionButton = new CmdButton(" N ");
	private CmdButton gaussSelectionButton = new CmdButton(" G ");
	
	private CmdButton distortButton = new CmdButton(" D ");
	
	private JToolBar fileToolBar = new JToolBar();
	private CmdButton open = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Open16.gif")));
	private CmdButton save = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Save16.gif")));
	private CmdButton saveAs = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SaveAs16.gif")));
	
	// Componentes JavaHelp
	private HelpSet helpset;
	private HelpBroker helpbroker;
	
	private NumberFormat numberFormat;
	
//	*****************************************************************************
	/**
	 * The constructor method. <br>
	 * Calls the init() method throwing an exception.
	 */
	public DesktopPostp() {
		try {
			init();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//	*****************************************************************************
	/**
	 *  It's called by the constructor. <br>
	 *  Sets Panels, components and provides a window listener.
	 */
	private void init() throws Exception {
		
		addHelp("br/ufmg/dees/insane/help/postp/helpset.hs");
		linkHelp();
		
		this.setFonts();
		this.setTitle("INSANE POSTP " + this.getProperties().getVersion());
		this.setResizable(true);
		this.setSize(Toolkit.getDefaultToolkit().getScreenSize().width - 100, Toolkit.getDefaultToolkit().getScreenSize().height-100);
		this.setSize(new Dimension(800, 640));
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		
		this.getContentPane().setLayout(new BorderLayout());
		
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
//		this.addWindowListener(new WindowAdapter() {
//		public void windowClosing(WindowEvent e) {
//		this.DISPOSE_ON_CLOSE;
//		}
//		} );
		
		Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		
		toolPanel.setLayout(new BoxLayout(toolPanel, BoxLayout.LINE_AXIS));
		this.getContentPane().add(toolPanel, BorderLayout.NORTH);
		
		hToolPanel.setLayout(new BoxLayout(hToolPanel, BoxLayout.Y_AXIS));
		this.getContentPane().add(hToolPanel, BorderLayout.EAST);
		
		this.getContentPane().add(desktop);
		
		this.setUpFormat();
		
		//Setting Menus
		
		this.setJMenuBar(menuBar);
		menuBar.setBackground(Color.WHITE);
		menuBar.setForeground(Color.BLACK);
		
		//Setting menu file
		
		menuFile.setMnemonic(KeyEvent.VK_F);
		menuFile.add(itemOpen);
		itemOpen.setCommand(openCmd);
		itemOpen.addActionListener(this);
		itemOpen.setMnemonic(KeyEvent.VK_O);
		itemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
		
		menuFile.add(itemSave);
		itemSave.setCommand(saveFileCmd);
		itemSave.setEnabled(false);
		itemSave.addActionListener(this);
		itemSave.setMnemonic(KeyEvent.VK_S);
		itemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
		
		menuFile.add(itemSaveAs);
		itemSaveAs.setCommand(saveFileAsCmd);
		itemSaveAs.setEnabled(false);
		itemSaveAs.addActionListener(this);
		itemSaveAs.setMnemonic(KeyEvent.VK_A);
		itemSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.SHIFT_MASK));
		
		menuFile.addSeparator();
		
//		menuFile.add(itemPrint);
//		//itemPrint.setCommand(printCmd);
//		itemPrint.setEnabled(false);
//		itemPrint.addActionListener(this);
//		itemPrint.setMnemonic(KeyEvent.VK_P);
//		itemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
		
		menuFile.add(menuImport);
		menuImport.setMnemonic(KeyEvent.VK_I);
		
		menuImport.add(itemFemBinaryFiles);
		itemFemBinaryFiles.setCommand(importFemBinCmd);
		itemFemBinaryFiles.setEnabled(true);
		itemFemBinaryFiles.setMnemonic(KeyEvent.VK_B);
		itemFemBinaryFiles.addActionListener(this);
		
		menuImport.add(itemFemXMLFiles);
		itemFemXMLFiles.setCommand(importFemXMLCmd);
		itemFemXMLFiles.setEnabled(true);
		itemFemXMLFiles.setMnemonic(KeyEvent.VK_F);
		itemFemXMLFiles.addActionListener(this);
		
		menuImport.add(itemPostpXMLFiles);
		itemPostpXMLFiles.setCommand(importPostpXMLCmd);
		itemPostpXMLFiles.setEnabled(true);
		itemPostpXMLFiles.setMnemonic(KeyEvent.VK_P);
		itemPostpXMLFiles.addActionListener(this);
		
		menuFile.add(menuExport);
		menuExport.setEnabled(false);
		menuExport.setMnemonic(KeyEvent.VK_E);
		
		menuExport.add(itemPNG);
		itemPNG.setCommand(exportPNGCmd);
		itemPNG.setMnemonic(KeyEvent.VK_J);
		itemPNG.addActionListener(this);
		
		menuExport.add(itemJPEG);
		itemJPEG.setCommand(exportJPEGCmd);
		itemJPEG.setMnemonic(KeyEvent.VK_J);
		itemJPEG.addActionListener(this);
		
		/* menuExport.add(itemPDF);
		 itemPDF.setCommand(exportPDFCmd);
		 itemPDF.setMnemonic(KeyEvent.VK_P);
		 itemPDF.addActionListener(this);
		 */
		
		menuExport.add(itemPS);
		itemPS.setCommand(exportPSCmd);
		itemPS.setMnemonic(KeyEvent.VK_P);
		itemPS.addActionListener(this);
		
		menuExport.add(itemXML);
		itemXML.setCommand(exportXMLCmd);
		itemXML.setMnemonic(KeyEvent.VK_X);
		itemXML.addActionListener(this);
		
		menuFile.add(menuLoad);
		menuLoad.setEnabled(true);
		menuLoad.setMnemonic(KeyEvent.VK_E);
		
		menuLoad.add(itemLoadFemBinFile);
		itemLoadFemBinFile.setCommand(loadFemModelBinCmd);
		itemLoadFemBinFile.setMnemonic(KeyEvent.VK_B);
		itemLoadFemBinFile.addActionListener(this);
		
		menuLoad.add(itemLoadFemXMLFile);
		itemLoadFemXMLFile.setCommand(loadFemModelXMLCmd);
		itemLoadFemXMLFile.setMnemonic(KeyEvent.VK_F);
		itemLoadFemXMLFile.addActionListener(this);
		
		menuLoad.add(itemLoadPostpXMLFile);
		itemLoadPostpXMLFile.setCommand(loadPostpXMLCmd);
		itemLoadPostpXMLFile.setMnemonic(KeyEvent.VK_P);
		itemLoadPostpXMLFile.addActionListener(this);
		
		menuFile.addSeparator();
		
		menuFile.add(itemExit);
		itemExit.setMnemonic(KeyEvent.VK_X);
		itemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
		itemExit.setCommand(exitCmd);
		itemExit.addActionListener(this);
		
		//Setting menu View
		menuView.setMnemonic(KeyEvent.VK_M);
		
		menuView.add(itemModelsSelection);
		itemModelsSelection.setCommand(modelSelectionCmd);
		itemModelsSelection.setMnemonic(KeyEvent.VK_S);
		itemModelsSelection.addActionListener(this);
		
		menuView.addSeparator();
		
		menuView.add(itemDisplay);
		itemDisplay.setCommand(displayCmd);
		itemDisplay.setMnemonic(KeyEvent.VK_S);
		itemDisplay.addActionListener(this);
		
		menuView.addSeparator();
		
		menuZoom.add(itemWindow);
		itemWindow.setToolTipText("Window");
		itemWindow.setText("Window");
        itemWindow.setCommand(zoomCmd);
        itemWindow.addActionListener(this);
        itemWindow.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.SHIFT_MASK));
        
        menuZoom.add(itemZoomIn);
        itemZoomIn.setToolTipText("In");
        itemZoomIn.setText("In");
        itemZoomIn.setCommand(zoomInCmd);
        itemZoomIn.addActionListener(this);
        itemZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ActionEvent.SHIFT_MASK));
		
        menuZoom.add(itemZoomOut);
        itemZoomOut.setToolTipText("Out");
        itemZoomOut.setText("Out");
        itemZoomOut.setCommand(zoomOutCmd);
        itemZoomOut.addActionListener(this);
        itemZoomOut.setAccelerator(KeyStroke.getKeyStroke("MINUS"));
        
        menuZoom.add(itemAll);
        itemAll.setToolTipText("All");
        itemAll.setText("All");
        itemAll.setCommand(zoomAllCmd);
        itemAll.addActionListener(this);
        itemAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.SHIFT_MASK));
		
		menuZoom.add(itemExtents);
		itemExtents.setToolTipText("Extends");
		itemExtents.setText("Extends");
        itemExtents.setCommand(fitCmd);
        itemExtents.addActionListener(this);
        itemExtents.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.SHIFT_MASK));
        
        menuZoom.add(itemLastZoom);
        itemLastZoom.setToolTipText("Last");
        itemLastZoom.setText("Last");
        itemLastZoom.setCommand(lastZoomCmd);
        itemLastZoom.addActionListener(this);
        itemLastZoom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.SHIFT_MASK));
        
        menuZoom.add(itemRedraw);
        itemRedraw.setToolTipText("Redraw");
        itemRedraw.setText("Redraw");
        itemRedraw.setCommand(redrawCmd);
        itemRedraw.addActionListener(this);
        itemRedraw.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.SHIFT_MASK));
		
		menuView.add(menuZoom);
			
//		menuView.add(itemProjections);
//		itemProjections.setCommand(projectionsCmd);
//		itemProjections.setMnemonic(KeyEvent.VK_M);
//		itemProjections.addActionListener(this);
		
//		menuView.add(itemRotation);
//		itemRotation.setCommand(rotationCmd);
//		itemRotation.setMnemonic(KeyEvent.VK_M);
//		itemRotation.addActionListener(this);
		
		menuView.add(itemMove);
		itemMove.setCommand(moveCmd);
		itemMove.setMnemonic(KeyEvent.VK_M);
		itemMove.addActionListener(this);
		
		menuView.addSeparator();
		
		menuView.add(itemViewGlobalAxis);
		itemViewGlobalAxis.setCommand(viewGlobalAxisCmd);
		itemViewGlobalAxis.setMnemonic(KeyEvent.VK_M);
		itemViewGlobalAxis.addActionListener(this);
		
		//Setting menu Settings
		menuSettings.setMnemonic(KeyEvent.VK_S);
		
		menuSettings.add(itemGenSettings);
		itemGenSettings.setCommand(genSettingsCmd);
		itemGenSettings.setMnemonic(KeyEvent.VK_G);
		itemGenSettings.addActionListener(this);
		
		menuSettings.addSeparator();
		
		menuSettings.add(itemFaceSettings);
		itemFaceSettings.setCommand(faceSettingsCmd);
		itemFaceSettings.setMnemonic(KeyEvent.VK_F);
		itemFaceSettings.addActionListener(this);
		
		menuSettings.add(itemEdgesSettings);
	//	itemEdgesSettings.setCommand(edgeSettingsCmd);
		itemEdgesSettings.setMnemonic(KeyEvent.VK_G);
		itemEdgesSettings.addActionListener(this);
		
		menuSettings.add(itemVertexSettings);
		itemVertexSettings.setCommand(verticesSettingsCmd);
		itemVertexSettings.setMnemonic(KeyEvent.VK_G);
		itemVertexSettings.addActionListener(this);
		
//		menuSettings.add(itemViewAttributesSettings);
//		itemViewAttributesSettings.setCommand(viewSettingsCmd);
//		itemViewAttributesSettings.setMnemonic(KeyEvent.VK_G);
//		itemViewAttributesSettings.addActionListener(this);
		
		menuSettings.addSeparator();
		
//		menuSettings.add(itemRestraints);
//		itemRestraints.setCommand(restraintsSettingsCmd);
//		itemRestraints.setMnemonic(KeyEvent.VK_H);
//		itemRestraints.addActionListener(this);
		
//		menuSettings.add(itemLoads);
//		itemLoads.setCommand(loadsSettingsCmd);
//		itemLoads.setMnemonic(KeyEvent.VK_H);
//		itemLoads.addActionListener(this);
		
		menuSettings.add(itemScaleColorsSettings);
		itemScaleColorsSettings.setCommand(scaleColorsSettingsCmd);
		itemScaleColorsSettings.setMnemonic(KeyEvent.VK_H);
		itemScaleColorsSettings.addActionListener(this);
		
		menuSettings.addSeparator();
		
//		menuSettings.add(itemGraphicsSettings);
//		itemGraphicsSettings.setCommand(graphicSettingsCmd);
//		itemGraphicsSettings.setMnemonic(KeyEvent.VK_H);
//		itemGraphicsSettings.addActionListener(this);
		
		//Setting menu ViewResults
		menuResults.setMnemonic(KeyEvent.VK_T);
		
		menuNodalResults.add(itemNodalPlotContours);
		itemNodalPlotContours.setCommand(nodalPlotContoursCmd);
		itemNodalPlotContours.setMnemonic(KeyEvent.VK_L);
		itemNodalPlotContours.addActionListener(this);
		
		menuNodalResults.add(itemNodalVector);
		itemNodalVector.setCommand(vectorsResultsNodalsCmd);
		itemNodalVector.setMnemonic(KeyEvent.VK_I);
		itemNodalVector.addActionListener(this);
		
		menuNodalResults.add(itemNodalEigenvalues);
		itemNodalEigenvalues.setCommand(eigevaluesNodalsCmd);
		itemNodalEigenvalues.setMnemonic(KeyEvent.VK_I);
		itemNodalEigenvalues.addActionListener(this);
		
		menuResults.add(menuNodalResults);
		
		menuElementResults.add(itemElementsPlotContours);
		itemElementsPlotContours.setCommand(elementsPlotContoursCmd);
		itemElementsPlotContours.setMnemonic(KeyEvent.VK_R);
		itemElementsPlotContours.addActionListener(this);
		
		menuElementResults.add(itemDiscontinuosElementsPlotContours);
		itemDiscontinuosElementsPlotContours.setCommand(discontinuosElementsPlotContoursCmd);
		itemDiscontinuosElementsPlotContours.setMnemonic(KeyEvent.VK_R);
		itemDiscontinuosElementsPlotContours.addActionListener(this);
		
		menuElementResults.add(itemElementEigenvalues);
		itemElementEigenvalues.setCommand(eigevaluesElementsCmd);
		itemElementEigenvalues.setMnemonic(KeyEvent.VK_R);
		itemElementEigenvalues.addActionListener(this);
		
		menuElementResults.add(itemElementVector);
		itemElementVector.setCommand(vectorsResultsElementssCmd);
		itemElementVector.setMnemonic(KeyEvent.VK_R);
		itemElementVector.addActionListener(this);
		
		menuResults.add(menuElementResults);
		
		menuResults.add(itemGraph);
		itemGraph.setCommand(graphicCmd);
		itemGraph.setMnemonic(KeyEvent.VK_G);
		itemGraph.addActionListener(this);
		
		menuResults.add(itemMeshState);
		itemMeshState.setCommand(meshStateListCmd);
		itemMeshState.setMnemonic(KeyEvent.VK_D);
		itemMeshState.addActionListener(this);
		
		menuResults.add(itemInformation);
		itemInformation.setCommand(informationCmd);
		itemInformation.setMnemonic(KeyEvent.VK_D);
		itemInformation.addActionListener(this);
		
		menuHelp.setMnemonic(KeyEvent.VK_F);
		menuHelp.add(itemHelp);
		itemHelp.setCommand(helpCmd);
		itemHelp.addActionListener(this);
		
		//Setting tools
		
		//Setting Zoom bar
		zoomToolBar.setFloatable(true);
		
		zoomToolBar.add(zoom);
		zoom.setToolTipText("Zoom Window");
		zoom.setCommand(zoomCmd);
		zoom.addActionListener(this);
		
		zoomToolBar.add(zoomIn);
		zoomIn.setToolTipText("Zoom In");
		zoomIn.setCommand(zoomInCmd);
		zoomIn.addActionListener(this);
		
		zoomToolBar.add(zoomOut);
		zoomOut.setToolTipText("Zoom Out");
		zoomOut.setCommand(zoomOutCmd);
		zoomOut.addActionListener(this);
		
		zoomToolBar.add(zoomAll);
		zoomAll.setToolTipText("Zoom All");
		zoomAll.setCommand(zoomAllCmd);
		zoomAll.addActionListener(this);
		
		zoomToolBar.add(fit);
		fit.setToolTipText("Zoom Extents");
		fit.setCommand(fitCmd);
		fit.addActionListener(this);
		
		zoomToolBar.add(zoomPrevious);
		zoomPrevious.setToolTipText("Zoom Last");
		zoomPrevious.setCommand(lastZoomCmd);
		zoomPrevious.addActionListener(this);
		
		zoomToolBar.add(redraw);
		redraw.setToolTipText("Redraw");
		redraw.setCommand(redrawCmd);
		redraw.addActionListener(this);
		
		//ViewToolBar
		
		planBar.setFloatable(true);
		planBar.setRollover(true);
		
		planBar.setSize(325,30);
		planBar.setMinimumSize(new Dimension(325,30));
		planBar.setMaximumSize(new Dimension(325,30));
		planBar.setPreferredSize(new Dimension(325,30));
		
		planBar.add(xyPlanButton);
		xyPlanButton.setToolTipText("XY");
		xyPlanButton.setCommand(setPlanXYCmd);
		xyPlanButton.addActionListener(this);
		
		planBar.add(xzPlanButton);
		xzPlanButton.setToolTipText("XZ");
		xzPlanButton.setCommand(setPlanXZCmd);
		xzPlanButton.addActionListener(this);
		
		planBar.add(yzPlanButton);
		yzPlanButton.setToolTipText("YZ");
		yzPlanButton.setCommand(setPlanYZCmd);
		yzPlanButton.addActionListener(this);
		
		planBar.add(perspectiveButton);
		perspectiveButton.setToolTipText("Perspective");
		perspectiveButton.setCommand(setPerspectiveCmd);
		perspectiveButton.addActionListener(this);
		
		planBar.add(new JLabel(" "));
		
		planBar.add(xRotationButton);
		xRotationButton.setToolTipText("Rotation in X");
		xRotationButton.setCommand(setRotationXCmd);
		xRotationButton.addActionListener(this);
		
		planBar.add(yRotationButton);
		yRotationButton.setToolTipText("Rotation in Y");
		yRotationButton.setCommand(setRotationYCmd);
		yRotationButton.addActionListener(this);
		
		planBar.add(zRotationButton);
		zRotationButton.setToolTipText("Rotation in Z");
		zRotationButton.setCommand(setRotationZCmd);
		zRotationButton.addActionListener(this);
		
		planBar.add(new JLabel("  "));
		
		planBar.setSize(new Dimension(400,35));
		planBar.setMaximumSize(new Dimension(400,35));
		planBar.setMinimumSize(new Dimension(400,35));
		planBar.setPreferredSize(new Dimension(400,35));
		
		setAngleStepField = new DecimalField(((PostpViewState)this.view.getViewState()).getGeoTransformViewState().getAngleStep(),10,numberFormat);
		setAngleStepField.setSize(35,25);
		setAngleStepField.setMinimumSize(new Dimension(35,25));
		setAngleStepField.setMaximumSize(new Dimension(35,25));
		setAngleStepField.setPreferredSize(new Dimension(35,25));
		setAngleStepField.setEditable(true);
		setAngleStepField.setBackground(Color.WHITE);
		setAngleStepField.setHorizontalAlignment(JTextField.CENTER);
		planBar.add(setAngleStepField);
		setAngleStepField.setToolTipText("Angle Step");
		setAngleStepField.addActionListener(this);
		
		//Setting stepModeBar tool bar
		stepModeBar.setFloatable(true);
		
		stepModeBar.setSize(new Dimension(550,35));
		stepModeBar.setMaximumSize(new Dimension(550,35));
		stepModeBar.setMinimumSize(new Dimension(550,35));
		stepModeBar.setPreferredSize(new Dimension(550,35));
		
		stepModeBar.add(backwardButton);
		backwardButton.setToolTipText("<< - step");
		backwardButton.setCommand(backwardStepCmd);
		backwardButton.setMnemonic(KeyEvent.VK_B);
		backwardButton.addActionListener(this);
		
		currentStepField = new DecimalField(((PostpViewState)this.view.getViewState()).getStepState().currentStep,10,numberFormat);
		currentStepField.setSize(30,25);
		currentStepField.setMinimumSize(new Dimension(30,25));
		currentStepField.setMaximumSize(new Dimension(30,25));
		currentStepField.setPreferredSize(new Dimension(30,25));
		currentStepField.setEditable(false);
		currentStepField.setBackground(Color.WHITE);
		currentStepField.setHorizontalAlignment(JTextField.CENTER);
		stepModeBar.add(currentStepField);
		currentStepField.setToolTipText("Current Step");
		currentStepField.addActionListener(this);
		
		stepModeBar.add(forwardButton);
		forwardButton.setToolTipText("step + >>");
		forwardButton.setCommand(forwardStepCmd);
		forwardButton.setMnemonic(KeyEvent.VK_F);
		forwardButton.addActionListener(this);
		
		stepModeBar.add(new JLabel("   "));
		
		stepModeBar.add(goToStepButton);
		goToStepButton.setToolTipText("Set Step");
		goToStepButton.setCommand(setStepCmd);
		goToStepButton.addActionListener(this);
		
		setStepField = new DecimalField(((PostpViewState)this.view.getViewState()).getStepState().currentStep,10,numberFormat);
		setStepField.setSize(30,10);
		setStepField.setMinimumSize(new Dimension(30,25));
		setStepField.setMaximumSize(new Dimension(30,25));
		setStepField.setPreferredSize(new Dimension(30,25));
		setStepField.setEditable(true);
		setStepField.setBackground(Color.WHITE);
		setStepField.setHorizontalAlignment(JTextField.CENTER);
		stepModeBar.add(setStepField);
		setStepField.setToolTipText("Set Step");
		setStepField.addActionListener(this);
		
		stepModeBar.add(new JLabel("  "));
		
		stepModeBar.add(startButton);
		startButton.setToolTipText("Start");
		startButton.setCommand(startAnimationStepCmd);
		startButton.addActionListener(this);
		
		stepModeBar.add(stopButton);
		stopButton.setToolTipText("Stop");
		stopButton.setCommand(stopAnimationStepCmd);
		stopButton.addActionListener(this);
		
		//Setting file tool bar
		fileToolBar.add(open);
		open.setToolTipText("Open Model");
		open.setCommand(openCmd);
		open.addActionListener(this);
		
		fileToolBar.add(save);
		save.setToolTipText("Save Model");
		save.setCommand(saveFileCmd);
		save.addActionListener(this);
		
		fileToolBar.add(saveAs);
		saveAs.setToolTipText("Save Model As");
		saveAs.setCommand(saveFileAsCmd);
		saveAs.addActionListener(this);
		
		//Setting teste tool bar
		vToolBar.setFloatable(false);
		vToolBar.setSize(new Dimension(35,800));
		vToolBar.addSeparator();
		
		upButton.setFont(new Font("Arial",Font.PLAIN,8));
		upButton.setSize(35,30);
		upButton.setPreferredSize(new Dimension(35,30));
		upButton.setMinimumSize(new Dimension(35,30));
		upButton.setMaximumSize(new Dimension(35,30));
		upButton.setToolTipText("Up");
		upButton.setCommand(moveUpCmd);
		upButton.addActionListener(this);
		vToolBar.add(upButton);
		
		leftButton.setFont(new Font("Arial",Font.PLAIN,8));
		leftButton.setSize(35,30);
		leftButton.setPreferredSize(new Dimension(35,30));
		leftButton.setMinimumSize(new Dimension(35,30));
		leftButton.setMaximumSize(new Dimension(35,30));
		leftButton.setToolTipText("Left");
		leftButton.setCommand(moveLeftCmd);
		leftButton.addActionListener(this);
		vToolBar.add(leftButton);
		
		rightButton.setFont(new Font("Arial",Font.PLAIN,8));
		rightButton.setSize(35,35);
		rightButton.setPreferredSize(new Dimension(35,30));
		rightButton.setMinimumSize(new Dimension(35,30));
		rightButton.setMaximumSize(new Dimension(35,30));
		rightButton.setToolTipText("Right");
		rightButton.setCommand(moveRightCmd);
		rightButton.addActionListener(this);
		vToolBar.add(rightButton);
		
		downButton.setFont(new Font("Arial",Font.PLAIN,8));
		downButton.setSize(35,30);
		downButton.setPreferredSize(new Dimension(35,30));
		downButton.setMinimumSize(new Dimension(35,30));
		downButton.setMaximumSize(new Dimension(35,30));
		downButton.setToolTipText("Down");
		downButton.setCommand(moveDownCmd);
		downButton.addActionListener(this);
		vToolBar.add(downButton);
		
		JLabel label = new JLabel("Factor");
		label.setFont(new Font("Arial",Font.PLAIN,8));
		vToolBar.add(label);
				
		setMoveStepField = new DecimalField(1,10,numberFormat);
		setMoveStepField.setSize(60,30);
//		setMoveStepField.setMinimumSize(new Dimension(35,30));
		setMoveStepField.setMaximumSize(new Dimension(60,30));
		setMoveStepField.setPreferredSize(new Dimension(60,30));
		setMoveStepField.setEditable(true);
		setMoveStepField.setBackground(Color.WHITE);
		setMoveStepField.setHorizontalAlignment(JTextField.CENTER);
		setMoveStepField.setToolTipText("Translation Factor");
		setMoveStepField.addActionListener(this);
		setMoveStepField.setAlignmentX(0.0F);
		setMoveStepField.setAlignmentY(0.0F);
		vToolBar.add(setMoveStepField);
		
		vToolBar.addSeparator();
		
		nodalResultsButton.setSize(35,30);
		nodalResultsButton.setPreferredSize(new Dimension(35,30));
		nodalResultsButton.setMinimumSize(new Dimension(35,30));
		nodalResultsButton.setMaximumSize(new Dimension(35,30));
		nodalResultsButton.setToolTipText("Nodal Contours");
		nodalResultsButton.setCommand(nodalPlotContoursCmd);
		nodalResultsButton.addActionListener(this);
		vToolBar.add(nodalResultsButton);
		
		vToolBar.addSeparator();
		
		elementsResultsButton.setSize(35,30);
		elementsResultsButton.setPreferredSize(new Dimension(35,30));
		elementsResultsButton.setMinimumSize(new Dimension(35,30));
		elementsResultsButton.setMaximumSize(new Dimension(35,30));
		elementsResultsButton.setToolTipText("Element Contours");
		elementsResultsButton.setCommand(elementsPlotContoursCmd);
		elementsResultsButton.addActionListener(this);
		vToolBar.add(elementsResultsButton);
		
		vToolBar.addSeparator();
		
		meshStateButton.setSize(35,30);
		meshStateButton.setPreferredSize(new Dimension(35,30));
		meshStateButton.setMinimumSize(new Dimension(35,30));
		meshStateButton.setMaximumSize(new Dimension(35,30));
		meshStateButton.setToolTipText("Mesh State");
		meshStateButton.setCommand(meshStateListCmd);
		meshStateButton.addActionListener(this);
		vToolBar.add(meshStateButton);
		
		graphButton.setSize(35,30);
		graphButton.setPreferredSize(new Dimension(35,30));
		graphButton.setMinimumSize(new Dimension(35,30));
		graphButton.setMaximumSize(new Dimension(35,30));
		graphButton.setToolTipText("Add Graph");
		graphButton.setCommand(graphicCmd);
		graphButton.addActionListener(this);
		vToolBar.add(graphButton);
		
		infoButton.setSize(35,30);
		infoButton.setPreferredSize(new Dimension(35,30));
		infoButton.setMinimumSize(new Dimension(35,30));
		infoButton.setMaximumSize(new Dimension(35,30));
		infoButton.setToolTipText("Add Graph");
		infoButton.setCommand(informationCmd);
		infoButton.addActionListener(this);
		vToolBar.add(infoButton);
		
		vToolBar.addSeparator();
		
		elementSelctionButton.setSize(35,30);
		nodalSelectionButton.setSize(35,30);
		gaussSelectionButton.setSize(35,30);
		distortButton.setSize(35,30);
		elementSelctionButton.setPreferredSize(new Dimension(35,30));
		nodalSelectionButton.setPreferredSize(new Dimension(35,30));
		gaussSelectionButton.setPreferredSize(new Dimension(35,30));
		distortButton.setPreferredSize(new Dimension(35,30));
		elementSelctionButton.setMinimumSize(new Dimension(35,30));
		nodalSelectionButton.setMinimumSize(new Dimension(35,30));
		gaussSelectionButton.setMinimumSize(new Dimension(35,30));
		distortButton.setMinimumSize(new Dimension(35,30));
		elementSelctionButton.setMaximumSize(new Dimension(35,30));
		nodalSelectionButton.setMaximumSize(new Dimension(35,30));
		gaussSelectionButton.setMaximumSize(new Dimension(35,30));
		distortButton.setMaximumSize(new Dimension(35,30));
		
		
		vToolBar.add(elementSelctionButton);
		elementSelctionButton.setToolTipText("");
		elementSelctionButton.setCommand(elementsSelectionCmd);
		elementSelctionButton.addActionListener(this);
		
		vToolBar.add(nodalSelectionButton);
		nodalSelectionButton.setToolTipText("");
		nodalSelectionButton.setCommand(nodesSelectionCmd);
		nodalSelectionButton.addActionListener(this);
		
		vToolBar.add(gaussSelectionButton);
		gaussSelectionButton.setToolTipText("");
		gaussSelectionButton.setCommand(gaussSelectionCmd);
		gaussSelectionButton.addActionListener(this);
		
		vToolBar.add(distortButton);
		distortButton.setToolTipText("");
		distortButton.setCommand(distortCmd);
		distortButton.addActionListener(this);
		//distortButton.setBounds(0,200,10,10);
		
		//newToolBar.add(panelField);
		this.setFonts();
		this.setInitialInterface();
		
	}
	
//	******************************************************************************
	
	public void setFonts() {
		try {
			UIManager.setLookAndFeel(UIManager.getInstalledLookAndFeels()[0].getClassName());
			Font fontCurrent = UIManager.getFont("Button.font");
			String name = fontCurrent.getName();
			
			//Creates similar font with the specified style and size
			FontUIResource fontResourceNew  = new FontUIResource(name, Font.PLAIN, 12);
			
			//Sets all items fonts
			UIManager.put("Button.font", fontResourceNew);
			UIManager.put("CheckBox.font", fontResourceNew);
			UIManager.put("CheckBoxMenuItem.font", fontResourceNew);
			UIManager.put("ColorChooser.font", fontResourceNew);
			UIManager.put("ComboBox.font", fontResourceNew);
			UIManager.put("DesktopIcon.font", fontResourceNew);
			UIManager.put("EditorPane.font", fontResourceNew);
			UIManager.put("InternalFrame.font", fontResourceNew);
			UIManager.put("Label.font", fontResourceNew);
			UIManager.put("List.font", fontResourceNew);
			UIManager.put("MenuBar.font", fontResourceNew);
			UIManager.put("Menu.font", fontResourceNew);
			UIManager.put("MenuItem.font", fontResourceNew);
			UIManager.put("OptionPane.font", fontResourceNew);
			UIManager.put("PasswordField.font", fontResourceNew);
			UIManager.put("PopupMenu.font", fontResourceNew);
			UIManager.put("ProgressBar.font", fontResourceNew);
			UIManager.put("RadioButton.font", fontResourceNew);
			UIManager.put("RadioButtonMenuItem.font", fontResourceNew);
			UIManager.put("ScrollPane.font", fontResourceNew);
			UIManager.put("TabbedPane.font", fontResourceNew);
			UIManager.put("TableHeader.font", fontResourceNew);
			UIManager.put("TextArea.font", fontResourceNew);
			UIManager.put("TextField.font", fontResourceNew);
			UIManager.put("TextPane.font", fontResourceNew);
			UIManager.put("TitledBorder.font", fontResourceNew);
			UIManager.put("ToggleButton.font", fontResourceNew);
			UIManager.put("ToolBar.font", fontResourceNew);
			UIManager.put("ToolTip.font", fontResourceNew);
			UIManager.put("Tree.font", fontResourceNew);
			UIManager.put("Viewport.font", fontResourceNew);
		}
		catch (Exception e){}
	}
	
//	******************************************************************************

	/** Returns the properties.
	 *@return The properties.
	 */
	public InsaneProperties getProperties() {
		return properties;
	}
	
	/** Returns the view.
	 *  @return The view.
	 */
	public IView getView() {
		return this.view;
	}
	
	/**
	 * The method sets the initial Interface
	 */
	public void setInitialInterface() {
		menuBar.removeAll();
		menuBar.add(menuFile);
		menuBar.add(menuView);
		menuBar.add(menuSettings);
		menuBar.add(menuResults);
		menuBar.add(menuHelp);
		
		menuView.setEnabled(false);
		menuSettings.setEnabled(false);
		menuResults.setEnabled(false);
		menuHelp.setEnabled(true);
		
		itemSave.setEnabled(false);
		itemSaveAs.setEnabled(false);
		itemPrint.setEnabled(false);
		menuExport.setEnabled(false);
		
		this.getJMenuBar().updateUI();
		
		desktop.removeAll();
		//desktop.add(new ImageDA(ClassLoader.getSystemResource("images/Insane.jpg")), BorderLayout.CENTER);
		desktop.setBackground(Color.GRAY);
		desktop.repaint();
		desktop.updateUI();
		
		toolPanel.removeAll();
		toolPanel.add(fileToolBar);
		
		this.setCoord("" + 0.0, "" + 0.0);
		
		this.repaint();
	}
	
	/**
	 * The method sets the Interface in use
	 */
	public void setInterface() {
		
		menuBar.removeAll();
		menuBar.add(menuFile);
		menuBar.add(menuView);
		menuBar.add(menuSettings);
		menuBar.add(menuResults);
		menuBar.add(menuHelp);
		
		menuView.setEnabled(true);
		menuSettings.setEnabled(true);
		menuResults.setEnabled(true);
		menuHelp.setEnabled(true);
		
		itemSave.setEnabled(true);
		itemSaveAs.setEnabled(true);
		itemPrint.setEnabled(true);
		menuExport.setEnabled(true);
		zoomToolBar.setEnabled(true);
		
		toolPanel.add(zoomToolBar);
		toolPanel.add(planBar);
		toolPanel.add(stepModeBar);
		vToolBar.setOrientation(1);
		
		hToolPanel.setSize(35,550);
		hToolPanel.setPreferredSize(new Dimension(35,550));
		hToolPanel.setMaximumSize(new Dimension(35,550));
		hToolPanel.setMinimumSize(new Dimension(35,550));
		
		//hToolPanel.setSize(new Dimension(30,50));
		hToolPanel.add(vToolBar);
		setAxisCheckBoxes();
	}
	
	/**
	 * The method sets the Interface in use
	 */
	public void setInterfaceCommands() {
		InterfacePostp intFrame = (InterfacePostp)desktop.getSelectedFrame();
		
		((ZoomCommand)this.zoomCmd).setParent(intFrame); 
		((ZoomInCommand)this.zoomInCmd).setParent((InterfacePostp)desktop.getSelectedFrame()); 
		((ZoomOutCommand)this.zoomOutCmd).setParent((InterfacePostp)desktop.getSelectedFrame()); 
		((FitCommand)this.fitCmd).setParent((InterfacePostp)desktop.getSelectedFrame()); 
		((ZoomAllCommand)this.zoomAllCmd).setParent((InterfacePostp)desktop.getSelectedFrame()); 
		((LastZoomCommand)this.lastZoomCmd).setParent((InterfacePostp)desktop.getSelectedFrame()); 
		((RedrawCommand)this.redrawCmd).setParent((InterfacePostp)desktop.getSelectedFrame()); 
		
		((SetPlanXYCommand)this.setPlanXYCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetPlanXZCommand)this.setPlanXZCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetPlanYZCommand)this.setPlanYZCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetPerspectiveCommand)this.setPerspectiveCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetRotationXCommand)this.setRotationXCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetRotationYCommand)this.setRotationYCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetRotationZCommand)this.setRotationZCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		
		((ForwardStepCommand)this.forwardStepCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((BackwardStepCommand)this.backwardStepCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((SetStepCommand)this.setStepCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((AnimationStartStepCommand)this.startAnimationStepCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		((AnimationStopStepCommand)this.stopAnimationStepCmd).setParent((InterfacePostp)desktop.getSelectedFrame());
		
		((MoveUpCommand)this.moveUpCmd).setIntFrame((InterfacePostp)desktop.getSelectedFrame());
		((MoveLeftCommand)this.moveLeftCmd).setIntFrame((InterfacePostp)desktop.getSelectedFrame());
		((MoveRightCommand)this.moveRightCmd).setIntFrame((InterfacePostp)desktop.getSelectedFrame());
		((MoveDownCommand)this.moveDownCmd).setIntFrame((InterfacePostp)desktop.getSelectedFrame());
		
		
	}
//	*****************************************************************************
	
	/** Adds a Command to the undoList.
	 * @param cmd a the desired command
	 * @throws PropertyVetoException 
	 **/
	public void addInternalFrame(JInternalFrame F){
		this.repaint();
		F.pack();
		F.setVisible(true);
		F.setIconifiable(true);
		F.setPreferredSize(new Dimension(desktop.getWidth(),desktop.getHeight()));
		F.setSize(this.getWidth()/2-18,this.getHeight()/2-this.menuBar.getHeight()-(int)(this.toolPanel.getHeight()/1.5));
		F.setLocation(0,0);
		
		if(internalFramesCount==0){
			F.setLocation(0,0);
			internalFramesCount++;
		}else if(internalFramesCount==1){
			F.setLocation(this.getWidth()/2-21,0);
			internalFramesCount++;
		}else if(internalFramesCount==2){
			F.setLocation(0,this.getHeight()/2-this.menuBar.getHeight()-(int)(this.toolPanel.getHeight()/1.5));
			internalFramesCount++;
		}else if(internalFramesCount==3){
			F.setLocation(this.getWidth()/2-21,this.getHeight()/2-this.menuBar.getHeight()-(int)(this.toolPanel.getHeight()/1.5));
			internalFramesCount = 0;
		}
		
		F.setResizable(true);
		F.setMaximizable(true);
		
		desktop.add(F);
		if(F instanceof InterfacePostp){
			((InterfacePostp)F).setDesktop(this);
		}
		
		try {
			F.setSelected(true);
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		}
		//(((InterfacePostp)F).getView()).getDrawingArea().setRightClickedCommand(new PopUpCommand((InterfacePostp)F));
		desktop.setVisible(true);
		desktop.repaint();
		desktop.updateUI();
		F.repaint();
		
	}

	//	******************************************************************************
	
	/** Adds a Command to the undoList.
	 * @param cmd a the desired command
	 **/
	public void addToUndo(Command cmd) {
		
	}
	
//	*****************************************************************************
	
	/** Adds a Command to the redoList.
	 * @param cmd a the desired command
	 */
	public void addToRedo(Command cmd) {
		
	}
	
//	*****************************************************************************
	
	/** Disables the redo command.*/
	public void nothingToRedo() {
		
	}
	
//	*****************************************************************************
	
	/** Disables the undo command.*/
	public void nothingToUndo() {
		
	}
	
//	*****************************************************************************
	
	/** Method which executes the desired action to each command.*/
	public void actionPerformed(ActionEvent evt) {
		this.setInterfaceCommands();
		CommandHolder obj = (CommandHolder)evt.getSource();
		obj.getCommand().execute();
	}
	
	public void windowListener(ActionEvent evt){
		this.elementSelctionButton.setBackground(Color.red);
	}
	
//	*****************************************************************************
	/** Sets the AxisCheckBoxes of this Interface. */
	public void setAxisCheckBoxes(){
		itemViewGlobalAxis.setSelected(((PostpViewState)this.view.getViewState()).isGlobalAxisOn());
	};
	
	/**
	 * Sets the Status Bar coord text.
	 * @param x The first "X" coordinate.
	 * @param y The second "Y" coordinate.
	 */
	public void setCoord(String x, String y) {
		
	}
	
	/**
	 * Sets the Status Bar message.
	 * @param str The text to be shown
	 */
	public void setMessage(String str) {
		
	}
	
	/**
	 * Sets the number formater
	 */
	private void setUpFormat() {
		numberFormat = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
		numberFormat.setMaximumFractionDigits(0);
	}
	
	/**
	 * @return Returns the views.
	 */
	public ArrayList getViews() {
		return views;
	}
	
	/**
	 * @param views The views to set.
	 */
	public void setViews(ArrayList views) {
		this.views = views;
	}
	
	/**
	 * @return Returns the desktop.
	 */
	public JDesktopPane getDesktop() {
		return desktop;
	}
	
	/**
	 * @param desktop The desktop to set.
	 */
	public void setDesktop(JDesktopPane desktop) {
		this.desktop = desktop;
	}
	
	/**
	 * The method return the modelList.
	 * @return Returns The modelList.
	 */
	public ModelList getModelList() {
		return modelList;
	}
	/**
	 * The method set the field modelList from the parameter modelList.
	 * @param modelList The modelList to set.
	 */
	public void setModelList(ModelList modelList) {
		this.modelList = modelList;
	}
	
	public DecimalField getSetAngleStepField() {
		return setAngleStepField;
	}
	
	public void setSetAngleStepField(DecimalField setAngleStepField) {
		this.setAngleStepField = setAngleStepField;
	}
	
	/**
	 * The method return the currentStepField.
	 * @return Returns The currentStepField.
	 */
	public DecimalField getCurrentStepField() {
		return currentStepField;
	}
	
	/**
	 * The method set the field currentStepField from the parameter currentStepField.
	 * @param currentStepField The currentStepField to set.
	 */
	public void setCurrentStepField(DecimalField currentStepField) {
		this.currentStepField = currentStepField;
	}
	
	/**
	 * The method return the setStepField.
	 * @return Returns The setStepField.
	 */
	public DecimalField getSetStepField() {
		return setStepField;
	}
	
	/**
	 * The method set the field setStepField from the parameter setStepField.
	 * @param setStepField The setStepField to set.
	 */
	public void setSetStepField(DecimalField setStepField) {
		this.setStepField = setStepField;
	}
	
	/**
	 * The method return the itemHelp.
	 * @return Returns The itemHelp.
	 */
	public CmdMenu getItemHelp() {
		return itemHelp;
	}
	/**
	 * The method set the field itemHelp from the parameter itemHelp.
	 * @param itemHelp The itemHelp to set.
	 */
	public void setItemHelp(CmdMenu itemHelp) {
		this.itemHelp = itemHelp;
	}
	/**
	 * The method return the menuHelp.
	 * @return Returns The menuHelp.
	 */
	public JMenu getMenuHelp() {
		return menuHelp;
	}
	/**
	 * The method set the field menuHelp from the parameter menuHelp.
	 * @param menuHelp The menuHelp to set.
	 */
	public void setMenuHelp(JMenu menuHelp) {
		this.menuHelp = menuHelp;
	}
	
	public void addHelp(String nomeHelpSet) {
		// Encontra o arquivo HelpSet e cria o HelpBroker
		ClassLoader loader = DesktopPostp.class.getClassLoader();
		try {
			URL url = HelpSet.findHelpSet(loader, nomeHelpSet);
			helpset = new HelpSet(loader, url);
			helpbroker = helpset.createHelpBroker();
		} catch (Exception e) {
			/* Tratar */
		}
	}
	
	public void linkHelp() {
		// Associa o t�pico 'indice' ao clique do menu Ajuda/Conte�do
		helpbroker.enableHelpOnButton(itemHelp, "indiceINSANE", helpset);
		// Associa o t�pico 'topico1' ao pressionamento da tecla F1 no painel principal
		helpbroker.enableHelpKey(this.getRootPane(), "indiceINSANE", helpset);
		
	}

	public CmdButton getElementSelectionButton() {
		return elementSelctionButton;
	}

	public void setElementSelctionButton(CmdButton elementSelctionButton) {
		this.elementSelctionButton = elementSelctionButton;
	}

	public CmdButton getNodalSelectionButton() {
		return nodalSelectionButton;
	}

	public void setNodalSelectionButton(CmdButton nodalSelectionButton) {
		this.nodalSelectionButton = nodalSelectionButton;
	}

	public CmdButton getGaussSelectionButton() {
		return gaussSelectionButton;
	}

	public void setGaussSelectionButton(CmdButton gaussSelectionButton) {
		this.gaussSelectionButton = gaussSelectionButton;
	}

	public CmdButton getDistortButton() {
		return distortButton;
	}

	public void setDistortButton(CmdButton distortButton) {
		this.distortButton = distortButton;
	}

	public DecimalField getSetMoveStepField() {
		return setMoveStepField;
	}

	public void setSetMoveStepField(DecimalField setMoveStepField) {
		this.setMoveStepField = setMoveStepField;
	}   
	
//	*********************************************************************************	
}//end of this class

